package main

import (
	"WeChatMGRA/modul"
	"WeChatMGRA/receive"
	"WeChatMGRA/requests"
	"fmt"
	"time"
)

func main(){
	logintwo,err:=requests.LoginTwo()
	if err !=nil{
		fmt.Println(err)
		return
	}
	defer func(){
		requests.QuitWx(logintwo.WID)
	}()
	fmt.Println(logintwo)
	//a:=1
	//fmt.Scanf("%d",&a)
	//fmt.Println("确认连接中")
	loginthree := new(modul.WXLoginThree)
	for i:=3;i>0;i-- {
		time.Sleep(time.Second*15)
		loginthree,err =requests.LoginThree(logintwo.WID)
		if err !=nil{
			fmt.Println(err)
		}else {
			fmt.Println(loginthree)
			break
		}
	}
	receive.Wid = loginthree.WID
	alllist := new(modul.ContactList)
	for{
		alllist,err =requests.GetContactList(logintwo.WID)
		if err !=nil{
			fmt.Println(err)
			return
		}
		if alllist == nil{
			fmt.Println("列表加载中")
			time.Sleep(time.Second*5)
		}else {
			for _,v:=range alllist.Groups{
				fmt.Println(v)
			}
			break
		}
	}
	receive.ReceiveGroup()
	for i:=10;i>0;i--{
		vurl,len := receive.Downmsg()
		if len==0{
			fmt.Println("长度为零")
			return
		}
		for _,v:=range  alllist.Groups {
			if requests.SendMsg(logintwo.WID,v.UserName,vurl,len) !=nil{
				fmt.Println("发送失败")
			}else{
				fmt.Println("发送成功")
			}
		}
	}
}
